package com.easy.base.domain;

import java.io.IOException;

import org.codehaus.jackson.map.ObjectMapper;

public class EObject implements Comparable<EObject> {

    private String oid;
    private String oname;
    private String odesc;


    private String creater;
    private String operater;
    private String last_modify_time;
        
    public String getId() {
		return oid;
	}

    public EObject(String oid) {
        this.oid = oid;
    }

    public EObject(String oid, String oname) {
        this.oid = oid;
        this.oname = oname;
    }

    public EObject() {
    }

    public String getTableName() {
        return getClass().getSimpleName();
    }

    public String generateOid() {
        if (this.oid == null) {
            this.oid = System.currentTimeMillis() + "_" + Math.random();
        }

        return this.oid;
    }

    public String getOid() {
        return oid;
    }

    public void setOid(String oid) {
        this.oid = oid;
        //this.id = oid;
    }

    public String getOname() {
        return oname;
    }

    public void setOname(String oname) {
        this.oname = oname;
    }

    public String getOdesc() {
        return odesc;
    }

    public void setOdesc(String odesc) {
        this.odesc = odesc;
    }

    public String getOperater() {
        return operater;
    }

    public void setOperater(String operater) {
        this.operater = operater;
    }

    public String getLast_modify_time() {
        return last_modify_time;
    }

    public void setLast_modify_time(String last_modify_time) {
        this.last_modify_time = last_modify_time;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String toString() {
        try {
            return new ObjectMapper().writeValueAsString(this);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return oid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EObject eObject = (EObject) o;

        if (creater != null ? !creater.equals(eObject.creater) : eObject.creater != null) return false;
        if (last_modify_time != null ? !last_modify_time.equals(eObject.last_modify_time) : eObject.last_modify_time != null)
            return false;
        if (odesc != null ? !odesc.equals(eObject.odesc) : eObject.odesc != null) return false;
        if (oid != null ? !oid.equals(eObject.oid) : eObject.oid != null) return false;
        if (oname != null ? !oname.equals(eObject.oname) : eObject.oname != null) return false;
        if (operater != null ? !operater.equals(eObject.operater) : eObject.operater != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = oid != null ? oid.hashCode() : 0;
        result = 31 * result + (oname != null ? oname.hashCode() : 0);
        result = 31 * result + (odesc != null ? odesc.hashCode() : 0);
        result = 31 * result + (creater != null ? creater.hashCode() : 0);
        result = 31 * result + (operater != null ? operater.hashCode() : 0);
        result = 31 * result + (last_modify_time != null ? last_modify_time.hashCode() : 0);
        return result;
    }

    @Override
    public int compareTo(EObject eObject) {
        return oname.compareTo(eObject.oname);
    }
}
